﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Honestysoft.Financing.Model;
using Honestysoft.BaseObject;

namespace Honestysoft.Financing.WebUI.Module.Project.Json
{
    /// <summary>
    /// GetProjectByID 的摘要说明
    /// </summary>
    public class GetProjectByID : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string id = context.Request.Params["ID"];
            string invDate = context.Request.Params["InvDate"];
            BD_Project project = new BaseBusinessLogic<BD_Project>().GetEntity(id);
            decimal sumAmountS = new Honestysoft.Financing.BusinessLogic.Audit("").GetAmountSByProject(id, Convert.ToDateTime(invDate));
            //概算|计划开工|计划竣工|实际开工|实际竣工|财政支付|投控审核(初审金额合计)|资金支付进度
            string res = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}",
                project.Investment.ToString("0.00"),
                project.PlanStart.HasValue ? project.PlanStart.Value.ToString("yyyy-MM-dd") : "",
                project.PlanEnd.HasValue ? project.PlanEnd.Value.ToString("yyyy-MM-dd") : "",
                project.StartDate.HasValue ? project.StartDate.Value.ToString("yyyy-MM-dd") : "",
                project.EndDate.HasValue ? project.EndDate.Value.ToString("yyyy-MM-dd") : "",
                project.TotalCapitalAmount.ToString("0.00"),//资本金到位金额=财政支付
                sumAmountS.ToString("0.00"),//投控已审核金额=初审金额累计
                project.Investment.ToString("0.00") == "0.00" ? "0.00" : ((project.TotalCapitalAmount + sumAmountS) / project.Investment * 100).ToString("0.00"));
            context.Response.Write(res);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}